
;(function (global){
	// 用户操作地址
	var CGI = {
		MD_USER_PASSWD	: window.frontPath + 'user/mdUserPasswd' // 修改用户密码
	};
	
	var PASSWD_ERROR = {
			USER_PASSWD 	: {
				NULL : '原始密码不能为空',
				ERROR: '密码长度应在6到16个字符之间'
			},
			NEW_USER_PASSWD  	: {
				NULL  : '新密码不能为空',
				ERROR : '新密码长度应在6到16个字符之间'
			},
			CONFIRM_USER_PASSWD : {
				NULL  : '确认密码不能为空',
				ERROR : '两次输入密码不一致'
			}
		};
		//初始化输入框默认提示组件
		$.placeholder.init();
	
		$.validation.init([{				//原始密码
			ele : $('#login-passwd [name="userPassword"]'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return PASSWD_ERROR.USER_PASSWD.NULL;
				}
				if(!$.check.isPwd(_val)){
					return PASSWD_ERROR.USER_PASSWD.ERROR;
				}
				return true;
			}
		},{									//新密码
			ele : $('#login-passwd [name="newUserPassword"]'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				if(_val == ''){
					return PASSWD_ERROR.NEW_USER_PASSWD.NULL;
				} 
				if(!$.check.isPwd(_val)){
					return PASSWD_ERROR.NEW_USER_PASSWD.ERROR;
				} 
				return true;
			}
		},{									//确认密码
			ele : $('#login-passwd #confirmUserPassword'),
			checkHandler : function (){
				var _val = $.trim(this.ele.val());
				var _pwd = $.trim($('[name="newUserPassword"]').val());
				
				if(_val == ''){
					return PASSWD_ERROR.CONFIRM_USER_PASSWD.NULL;
				} 
				if(_val !== _pwd){
					return PASSWD_ERROR.CONFIRM_USER_PASSWD.ERROR;
				} 
				return true;
			}
		}],$('#mdUserPasswd'));
		

	// 修改用户密码
	$('#mdUserPassWD').click(function (){
		var userPassword=document.getElementById("userPassword");
		var newUserPassword=document.getElementById("newUserPassword");
		var confirmUserPassword=document.getElementById("confirmUserPassword");
		if($.validation.isSuccess($('#mdUserPasswd'))){
		
			var dataStr = $.substitute('userPassword={userPassword}&newUserPassword={newUserPassword}&r={curTime}', {
				userPassword : userPassword.value,
				newUserPassword : newUserPassword.value,
				curTime : new Date().getTime()
			});
			$.ajax({
				url : CGI.MD_USER_PASSWD,
				method : 'POST',
				data : dataStr,
				success : function(result) {
					//var result =eval("("+data+")");
					if(result.retcode!='0')
					{
						return 	$.alert({
				    		status : 'error',
							basicTitle : result.retmsg
						});
					}
					return $.alert({
			    		status : 'ok',
						basicTitle : result.retmsg
					});  
				}
			});
		}
	}); 
})(window);